package Java.BlackHorse.a04FileTest;

import java.io.File;

public class Test4 {
    public static void main(String[] args) {
            File file = new File("C:\\Users\\W\\Desktop\\Study\\Java\\javs-se-practice-warehouse");
            long length = getLen(file);
        System.out.println(length+"字节");
    }
    /*
    * 获取文件夹的总大小
    * 参数 file
    * 返回值 long
    * */
    public static long getLen(File file){
        long len = 0;
        File[] files = file.listFiles();
        if(files == null) return len;
        for(File f : files){
            if(f.isFile()) {
                len += f.length();
            }else{
                len += getLen(f);
            }
        }
        return len;
    }

}
